package com.glzn.springboot03.mapper;

import com.glzn.springboot03.entity.RealData;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Lenovo
 */
@Mapper
public interface RealDataMapper {
	/**
	 * 查询所有
	 * @param deviceId
	 * @return
	 */
	@Select("SELECT * FROM real_data WHERE device_id=#{deviceId}")
	List<RealData> findAll(Integer deviceId);

	/**
	 * 根据类型查找
	 * @param type
	 * @param deviceId
	 * @return
	 */
	@Select("SELECT * FROM real_data WHERE type=#{type} AND device_id=#{deviceId}")
	List<RealData> findByType(String type, Integer deviceId);

	/**
	 * 插入数据
	 * @param realData
	 * @return
	 */
	@SelectKey(statement = "SELECT MAX(id)+1 FROM real_data", keyProperty = "id", before = true, resultType = int.class)
	@Insert("INSERT INTO real_data(id,type,name,value,extend,device_id) VALUES(#{id},#{type},#{name},#{value},#{extend},#{deviceId})")
	boolean insert(RealData realData);

	/**
	 * 删除全部
	 * @param deviceId
	 * @return
	 */
	@Delete("DELETE FROM real_data WHERE device_id=#{deviceId}")
	boolean deleteAll(Integer deviceId);
}
